﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using LikeUs.WebService.Contract;
using System.Data;
using UserDAL;
using MoviesDAL;

namespace LikeUs.WebService.Server
{
    /// <summary>
    /// Implementaion of the WS server
    /// </summary>
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single,
        ConcurrencyMode = ConcurrencyMode.Multiple)]
    public class WSInfoImpl : IWSInfo
    {

        UserAgent userAgent = new UserAgent();
        MovieAgent movieAgent = new MovieAgent();
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public DataTable GetAllMyFriends(int userid)
        {
            return userAgent.GetAllMyFriends(userid);
        }

        public DataTable getMoviesLearning(int userid,int limit)
        {
           return movieAgent.getMoviesLearning(userid,limit);
        }

        public void linkUserMovie(int userid, int movieid, float rating)
        {
            movieAgent.linkUserMovie(userid,movieid,rating);
        }

        public void userRelationsRoutine(UserData userData)
        {
            movieAgent.userRelationsRoutine(userData);
        }

        public DataTable myRatings(int userid)
        {
            return movieAgent.myRatings(userid);
        }

        public DataTable friendRatings(int friendid,int myid)
        {
            return movieAgent.friendRatings(friendid,myid);
        }

        public DataTable GetTopGroupMovies(int userid,int nlimit)
        {
            return movieAgent.GetTopGroupMovies(userid,nlimit);
        }

        public int CreateUser(UserData data)
        {
            return userAgent.Create(data);
        }

        public int CreateFBUser(string accesstoken, int requestedDistance)
        {
            return userAgent.FBCreate(accesstoken, requestedDistance);
        }

        public UserData GetUser(int userid , object additions)
        {
            userAgent.Fetch(userid,additions);
            return (UserData)userAgent.Data;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="data"></param>
        public void UpdateUserData(UserData data)
        {
            userAgent.Data = data;
            //TODO: should remove the data parameter from Update
            userAgent.Update(data);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        public void DeleteUserAccount(int id)
        {
            userAgent.Delete(id);
        }

        public int ValidateUserAccount(string username,string password, object additions)
        {   
            return userAgent.Validate(username,password,additions);
        }

        public List<string> getLog(int userid, int nlimit)
        {
            return userAgent.getLog(userid, nlimit);
        }

        public void log(int userid, string log)
        {
            userAgent.log(userid, log);
        }
    }
}
